package org.yookiee.support.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.yookiee.support.core.datasource.I18nDatasource;
import org.yookiee.support.core.datasource.local.impl.LocalDatasourceImpl;
import org.yookiee.support.toolkits.redis.CustomRedisService;
import org.yookiee.support.toolkits.redis.impl.CustomRedisServiceImpl;
import org.yookiee.support.enums.DatasourceType;
import org.yookiee.support.exceptions.NotSupportException;

import javax.annotation.Resource;

/**
 * FileName DatasourceConfig
 * Package org.yookiee.support.config
 * Description
 * author cpstory
 * create 2023-11-30 14:29
 * version V1.0
 */
@Slf4j
@Configuration
public class DatasourceConfig {

    @Resource
    EasyI18nProperties easyI18nProperties;

    @Primary
    @Bean
    public I18nDatasource i18nDatasource(){
        DatasourceType datasource = easyI18nProperties.getDatasource();
        switch (datasource) {
            case LOCAL:
                return new LocalDatasourceImpl();
            /*case REDIS:
                return customRedisService();*/
            default:
                throw new NotSupportException("sorry about to init this framework, we have not yet supported other databases");
        }

    }

    @Bean
    @ConditionalOnClass(name = "org.springframework.data.redis.core.StringRedisTemplate")
    public CustomRedisService customRedisService(){
        return new CustomRedisServiceImpl();
    }

}
